package com.hbase;

import cn.hutool.core.io.file.FileWriter;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * @author zhaoyi
 * @date 2020/9/27 10:22
 */
public class HbaseToHdfs2 {

    public static void main(String[] args) throws IOException {

        Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum", "blueview-s61,blueview-s63,blueview-s64");// zookeeper地址
        config.set("hbase.zookeeper.property.clientPort", "2181");// zookeeper端口
        Connection connection = ConnectionFactory.createConnection(config);

        Table table = connection.getTable(TableName.valueOf("ods:wbuser_dev"));

        Scan scan = new Scan();
        scan.addColumn("info".getBytes(), Bytes.toBytes("birthday"));

        ResultScanner scanner = table.getScanner(scan);
        for (Result result : scanner) {
            byte[] data = result.getValue("info".getBytes(), Bytes.toBytes("birthday"));
            long input = Bytes.toLong(data)*1000;

            String rowKey = Bytes.toString(result.getRow());

            Date date = new Date(input);
            System.out.println(date);

            Put put = new Put(Bytes.toBytes(rowKey));
            put.addColumn(Bytes.toBytes("info"),Bytes.toBytes("birthday"),Bytes.toBytes(input));
            table.put(put);

        }






        table.close();
        connection.close();


    }
}
